defmodule House.Web.ItemControllerTest do
  use House.Web.ConnCase

  alias House.BasicData

  @create_attrs %{address: "some address", around: "some around", bedroom: "120.5", fitment: "some fitment", floor: 42, gps: "some gps", heating: "some heating", investment: "some investment", kitchen: "120.5", license: "some license", livingroom: "120.5", loan: "some loan", name: "some name", noise: "some noise", service: "some service", stop: "some stop", summary: "some summary", sunshine: "some sunshine", terrace: "120.5", traffic: "some traffic", year: 42}
  @update_attrs %{address: "some updated address", around: "some updated around", bedroom: "456.7", fitment: "some updated fitment", floor: 43, gps: "some updated gps", heating: "some updated heating", investment: "some updated investment", kitchen: "456.7", license: "some updated license", livingroom: "456.7", loan: "some updated loan", name: "some updated name", noise: "some updated noise", service: "some updated service", stop: "some updated stop", summary: "some updated summary", sunshine: "some updated sunshine", terrace: "456.7", traffic: "some updated traffic", year: 43}
  @invalid_attrs %{address: nil, around: nil, bedroom: nil, fitment: nil, floor: nil, gps: nil, heating: nil, investment: nil, kitchen: nil, license: nil, livingroom: nil, loan: nil, name: nil, noise: nil, service: nil, stop: nil, summary: nil, sunshine: nil, terrace: nil, traffic: nil, year: nil}

  def fixture(:item) do
    {:ok, item} = BasicData.create_item(@create_attrs)
    item
  end

  test "lists all entries on index", %{conn: conn} do
    conn = get conn, item_path(conn, :index)
    assert html_response(conn, 200) =~ "Listing Items"
  end

  test "renders form for new items", %{conn: conn} do
    conn = get conn, item_path(conn, :new)
    assert html_response(conn, 200) =~ "New Item"
  end

  test "creates item and redirects to show when data is valid", %{conn: conn} do
    conn = post conn, item_path(conn, :create), item: @create_attrs

    assert %{id: id} = redirected_params(conn)
    assert redirected_to(conn) == item_path(conn, :show, id)

    conn = get conn, item_path(conn, :show, id)
    assert html_response(conn, 200) =~ "Show Item"
  end

  test "does not create item and renders errors when data is invalid", %{conn: conn} do
    conn = post conn, item_path(conn, :create), item: @invalid_attrs
    assert html_response(conn, 200) =~ "New Item"
  end

  test "renders form for editing chosen item", %{conn: conn} do
    item = fixture(:item)
    conn = get conn, item_path(conn, :edit, item)
    assert html_response(conn, 200) =~ "Edit Item"
  end

  test "updates chosen item and redirects when data is valid", %{conn: conn} do
    item = fixture(:item)
    conn = put conn, item_path(conn, :update, item), item: @update_attrs
    assert redirected_to(conn) == item_path(conn, :show, item)

    conn = get conn, item_path(conn, :show, item)
    assert html_response(conn, 200) =~ "some updated address"
  end

  test "does not update chosen item and renders errors when data is invalid", %{conn: conn} do
    item = fixture(:item)
    conn = put conn, item_path(conn, :update, item), item: @invalid_attrs
    assert html_response(conn, 200) =~ "Edit Item"
  end

  test "deletes chosen item", %{conn: conn} do
    item = fixture(:item)
    conn = delete conn, item_path(conn, :delete, item)
    assert redirected_to(conn) == item_path(conn, :index)
    assert_error_sent 404, fn ->
      get conn, item_path(conn, :show, item)
    end
  end
end
